package www.member.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.json.simple.JSONArray;
import org.json.simple.JSONObject;

import www.Action;
import www.ActionForward;
import www.member.MemberDTO;
import www.member.MemberMgr;
import www.utility.Utility;

public class MemberDelete implements Action {
     @Override
    public ActionForward execute(HttpServletRequest request, HttpServletResponse response) throws Throwable {
         System.out.println("memberdelete executed");
         
         String id = request.getParameter("id");
         System.out.println("id:"+id);
         request.setCharacterEncoding("euc-kr");
         
         MemberMgr mgr = new MemberMgr();

         JSONObject obj = new JSONObject(); 
         //JSONArray data = new JSONArray();

         Object delete = mgr.delete(id);
         //Iterator<Object> iter = list.iterator();   
         if((Integer)delete == 1){
              // while(iter.hasNext() == true){
                     JSONObject item = new JSONObject();
                     //MemberDTO dto = (MemberDTO)read;
                     
                     //item.put(, arg1)
                     
//                     item.put("id", dto.getId());
//                     item.put("introduce", Utility.toJS(dto.getIntroduce()));
//                     item.put("nickname", Utility.toJS(dto.getNickname()));
//                     item.put("profilephoto", dto.getProfilephoto());
//                     item.put("password", Utility.toJS(dto.getPassword()));
//                     item.put("email", Utility.toJS(dto.getEmail()));
//                     item.put("memlevel", Utility.toJS(dto.getMemlevel()));
                     
                    // data.add(item);
                //  } 
                 obj.put("code","success");
                 obj.put("message", "success.");
                 //obj.put("data",data);   
               
         }else{
               obj.put("code","error");
               obj.put("message", "error.");
           }
             
             System.out.print("Member: " +  obj);
             request.setAttribute("obj", obj);
            
             ActionForward forward = new ActionForward();
             forward.setRedirect(false);  // 
             forward.setPath("/obj.jsp");
             
             return forward;
     }
}
